package com.leng.controller;

import com.leng.entity.User;
import com.leng.service.UserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: 冷俊杰
 * @Description: TODO
 * @DateTime: 2022/7/8 13:30
 **/
@org.springframework.stereotype.Controller
public class Controller {
    //通过注解将UserService，自动注入进来
    @Resource
    private UserService userService;

    @RequestMapping("findUserByUserName")
    public ModelAndView findUserByUserName(String username) {
        List<User> userList = userService.findUserByUserName(username);
        System.out.println(userList);
        ModelAndView modelAndView = new ModelAndView();
        /*将数据存入到一个集合中，相当于以前的request.setAttribut*/
        modelAndView.addObject("userList", userList);
        /*跳转的页面*/
        modelAndView.setViewName("main");
        return modelAndView;
    }
}
